//
//  SaleReportsController.m
//  UI Demo
//
//  Created by Rainy Zou on 15/11/30.
//  Copyright © 2015年 Rainy Zou. All rights reserved.
//

#import "SaleReportsController.h"
#import "SaleReportsCell.h"

@interface SaleReportsController ()
@property (strong, nonatomic) NSArray *array;

@end

@implementation SaleReportsController


-(NSArray *)array
{
    if(_array == nil)
    {
        _array = @[@{@"name":@"酷宝贝 2015.11.28 - 2015.11.30",@"image":@"image4"}];
    }
    return _array;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    UIButton *btn = [[UIButton alloc]init];
    UIImage *imageNormal = [UIImage imageNamed:@"head_back_normal"];
    imageNormal = [imageNormal stretchableImageWithLeftCapWidth:20 topCapHeight:20];
    UIImage *imageSelected = [UIImage imageNamed:@"head_back_selected"];
    imageSelected = [imageSelected stretchableImageWithLeftCapWidth:20 topCapHeight:20];
    btn.contentEdgeInsets = UIEdgeInsetsMake(0, 15, 0, 15);
    [btn setBackgroundImage:imageNormal forState:UIControlStateNormal];
    [btn setBackgroundImage:imageSelected forState:UIControlStateHighlighted];
    
    NSString *back = @"返回";
    CGSize size = [back sizeWithAttributes:@{NSFontAttributeName:btn.titleLabel.font}];
    
    [btn setTitle:@"返回" forState:UIControlStateNormal];
    btn.titleLabel.textAlignment = NSTextAlignmentRight;
    
    [btn addTarget:self action:@selector(clickBack) forControlEvents:UIControlEventTouchUpInside];
    btn.bounds = CGRectMake(0, 0, size.width + 30 , 40);
    UIBarButtonItem *leftItem = [[UIBarButtonItem alloc]initWithCustomView:btn];
    self.navigationItem.leftBarButtonItem =leftItem;
    
    UITableView *tableView = [[UITableView alloc]init];
    tableView.dataSource = self;
    tableView.delegate = self;
    
    tableView.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
    
    NSLog(@"%lf",self.view.frame.size.width);
    
    [self.view addSubview:tableView];
}

-(void)clickBack
{
    [self.navigationController popToRootViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.array.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *reuseId = @"saleReports";
    NSDictionary *dict = self.array[indexPath.row];
    SaleReportsCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseId];
    if(cell ==nil){
        cell = [[SaleReportsCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseId];
    }
    
    cell.frame = CGRectMake(0, 0, tableView.frame.size.width, tableView.frame.size.height);
    
    [cell setCellWithName:dict[@"name"] image:dict[@"image"]];
    NSLog(@"cell width: %lf",cell.frame.size.width);
    return cell;
}




@end
